﻿using System;

namespace ServerSide.utils
{
    public class RandomNumber
    {
        private static string RandomString = "123456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ";
        private static Random Random = new Random(DateTime.Now.Second);
        private static Random _random = new Random();

        #region 产生随机字符串 GetRandomStr(int length)
        /// <summary>
        /// 产生随机字符串
        /// </summary>
        /// <param name="length">字符串长度</param>
        /// <returns></returns>
        public static string GetRandomStr(int length)
        {
            string retValue = string.Empty;
            for (int i = 0; i < length; i++)
            {
                int r = Random.Next(0, RandomString.Length - 1);
                retValue += RandomString[r];
            }
            return retValue;
        }
        #endregion

        #region 产生随机数 GetRandomInt(int min, int max)
        /// <summary>
        /// 产生随机数
        /// </summary>
        /// <param name="min">最小值</param>
        /// <param name="max">最大值</param>
        /// <returns></returns>
        public static int GetRandomInt(int min, int max)
        {
            return Random.Next(min, max);
        }
        #endregion

        #region 产生一个随机小数 +GetRandomDouble()
        /// <summary>
        /// 产生一个随机小数
        /// </summary>
        /// <returns></returns>
        public static double GetRandomDouble()
        {
            return _random.NextDouble();
        }
        #endregion
    }
}
